<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise-ajax</title>
</head>
<body>
    <script>
        function myAjax(url,data=null,type="GET"){
            return new Promise((resolve,reject)=>{
                $.ajax({
                    type,
                    url,
                    data,
                    success(data){
                        resolve(data);
                    },
                    error(err){
                        reject(err);
                    }
                })
            })

        }
        let ajax = new myAjax('api.douban.com');
        ajax.then(
            data=>{
                console.log(res);
            },
            err=>{
                console.log(err);
            }
        )
        // 反复使用
        ajax.then(
            data=>{
                console.log(res);
            },
            err=>{
                console.log(err);
            }
        )
    </script>
</body>
</html>